package co.yeye.test;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * Created by yeye on 15/2/16.
 */
public class PullActivityFragment extends Fragment{

    SwipeRefreshLayout layout;
    TextView text;

    public static PullActivityFragment newInstance(){
        PullActivityFragment fragment  = new PullActivityFragment();
        return fragment;
    }

    public PullActivityFragment(){

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //return super.onCreateView(inflater, container, savedInstanceState);
        View rootView = inflater.inflate(R.layout.pull_to_refresh_layout, container, false);

        setPullListener(rootView);

        return rootView;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    private void setPullListener(View view){
        layout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
        text = (TextView) view.findViewById(R.id.refresh_text);

        layout.setColorSchemeResources(android.R.color.holo_blue_light,
                android.R.color.holo_red_light, android.R.color.holo_orange_light,
                android.R.color.holo_green_light);

        layout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                text.setText("正在刷新");
                // text
                //layout.setRefreshing(false);
            }
        });
    }

}
